<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>分割数组</title>
</head>

<body>
  <script>
    var array = function (A) {
      let res = 0,
        leftMax = A[0], // 存贮左侧最大值
        nextMax = A[0]; // 遍历时存储指针的最大值
      for (let i = 1; i < A.length; i++) {
        nextMax = Math.max(nextMax, A[i]);
        if (A[i] >= leftMax) continue;
        res = i;
        leftMax = nextMax;
      }
      return res + 1
    };
    console.log(array([5, 0, 3, 8, 6]))
  </script>
</body>

</html>